<!DOCTYPE html>
<html lang="zh-CN" ng-app='he'>
	<head>
		<meta charset='utf-8' />
	
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>审批</title>
		<script type="text/javascript">
			is_local='{{local}}';
			function loadcss(cssfile) {
		        document.write('\<link rel="stylesheet" href="' + cssfile +'" type="text/css"/\>');
		    }
			function loadjs(script_filename) {
		        document.write('\<script language="javascript" type="text/javascript" src="' + script_filename + '"\>\</script\>');
		    }
		    if(!is_local){
			    static_url='/static';
		    }else{
			    static_url='../../../../static';
		    }
		    // 加载所有微信页面需要的js和css
		    loadjs(static_url+'/js/weixin_page.js')
		</script>
		<script type="text/javascript">
			var app = angular.module('he',['ngSanitize']);
			app.config(function($interpolateProvider) {
				  $interpolateProvider.startSymbol('[[');
				  $interpolateProvider.endSymbol(']]');
				});
			app.controller('content',function ($scope,$http,$location) {
				var msg_id = $location.search().id;
				// 设置body里面的变量
				if(is_local){
					$scope.leave={
						id:'123',
						name:'heylin',
						category:'sick',
						start_time:'2016-01-28 08:30',
						end_time:'2016-02-01 17:30',
						span:'1.5',
						reason:'i m polcie man',
						create_time:'2016-01-23 08:30',
					  	remark:'SDFSDF'
					}
					$scope.msg={status:'pending',
								category:'leave_check_pro',
								}
				}else{
					// 从服务器初始化
					var post_url='/attendance/ajax/';
					function init_from_server() {
						var post_data = {
								leave_check_msg_detail:{msg_id:msg_id},
							};  
						$http.post(post_url,post_data)
						.success(function(data, status, headers, config) { 
							var rt = data.leave_check_msg_detail;
							if (rt.status=='success'){
								$scope.leave=rt.leave_detail;
								$scope.msg=rt.msg_info;
							}else{
								info(rt.msg,function () {
									location='approve_history.html';
								});
							}
							
						}).error(function(data, status, headers, config) {  
						    //处理错误 
						    $scope.std='有错误,返回码为:'+status;
						});
					}
					init_from_server();
					//--------------------------------
					
				}
			$scope.approve=function (check) {
				var leave=$scope.leave;
				var msg=$scope.msg;
				var postData = {
						process_msg:{msg_id:msg_id,
									status:check},
						approve_leave:{leave_id:leave.id,
										check:check,
										leader_type:msg.category,
										note:leave.remark},
					};  
				$http.post(post_url,postData)
				.success(function(data, status, headers, config) {  
					if(data.approve_leave.status=='success'){
						info('successful submit',function () {
							window.location='approve_history.html';
						});
					}else{
						info(data.approve_leave.msg);
					}
				}).error(function(data, status, headers, config) {  
				    //处理错误 
				    $scope.std='有错误,返回码为:'+status;
				});
			}
			})
		</script>
	</head>
	<body ng-controller='content'>
		<!-----------------弹出框------------------------>
		<div ng-include src='"info_panel.html"'></div>
		
		<!-----------------在这里填写内容------------------------>
		<div class="container">
    <div class="row">
        <div class="col-xs-12 topBox">
            <p class="description"><span ng-bind='leave.name'></span> apply for <span ng-bind='leave.category'></span></p>
            <div class="timeFrame">
                <span class="timeBox">START</span>
                <span class="connect"></span>
                <span class="circlet"><span ng-bind='leave.span'></span> days</span>
                <span class="timeBox">END</span>
            </div>
        </div>
        <div class="col-xs-12 group">
            <label class="lag col-xs-5">Start Time : </label>
            <span class="col-xs-7" ng-bind='leave.start_time'>2016-01-28 08:30</span>
        </div>
        <div class="col-xs-12 group">
            <label class="lag col-xs-5">End Time : </label>
            <span class="col-xs-7" ng-bind='leave.end_time'>2016-02-01 17:30</span>
        </div>
        <div class="col-xs-12 group">
            <label class="lag col-xs-5">Reason : </label>
            <span class="col-xs-7" ng-bind='leave.reason'>回家探亲,请领导批准</span>
        </div>
        <div class="col-xs-12 group">
            <label class="lag col-xs-5">Application Date : </label>
            <span class="col-xs-7" ng-bind='leave.create_time'>2016-01-25 14:32</span>
        </div>
        <div class="col-xs-12 group" >
				<label class="lag col-xs-5">AppState ：</label>
				<span class="col-xs-7" >
					<span ng-repeat='leader in leave.leaders'>
						 <span ng-bind='leader.name'></span>- <span ng-bind='leader.status'></span> <span class="timeStyle">2016-01-12 10:20</span>
						 <!-- -->
						<p ng-bind='leader.note'>dgsd</p>
					</span>

				</span>
		</div>
        <div class="col-xs-12 group" ng-show='msg.status=="pending"'>
            <label class="lag col-xs-5">Remarks ：</label>
            <!--<span class="col-xs-7" ng-show='msg.status!="pending"' ng-bind='leave.remark'>我的remark</span>-->
            <textarea class="col-xs-7 tear" rows="4" ng-model='leave.remark' ></textarea>
           
        </div>
        
			
        <div class="col-xs-12 btnBox">
            <button type="button" class="btn btn-default" ng-click='approve("approved")' ng-show='msg.status=="pending"'>APPROVE</button>
            <button type="button" class="btn btn-default" style="margin-left: 15px" ng-click='approve("rejected")' ng-show='msg.status=="pending"'>DISAPPROVE</button>
        </div>
        
    </div>
</div>
		
	</body>
</html>